package com.unionftech.common.utils

import java.util.regex.Pattern

class RegexUtils {
    companion object {
        /**
         * 邮箱正则
         */
        const val EMAIL_REGEX =
            "^[a-z0-9A-Z._%+-]+@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[A-Za-z0-9]{2,}$"

        /**
         * 验证码正则
         */
        const val VERIFYCODE_REGEX = "^\\d{4,6}$"

        /**
         * 密码校验
         */
        const val PASSWORD_REGEX =
            "^(?=.*[a-z])(?=.*[A-Z])[^\\s]{6,20}$|^(?=.*[a-z])(?=.*\\d)[^\\s]{6,20}$|^(?=.*[A-Z])(?=.*\\d)[^\\s]{6,20}$"

        /**
         * 交易密码的正则
         */
        const val TRADE_PASSWORD_REGEX =
            "^(?=.*[A-Z])(?=.*[a-z])(?=.*\\d)(?=.*[&\$#!?=_%+\\-@()<>*])[A-Za-z\\d&\$#!?=_%+\\-@()<>*]{8,15}$"

        /**
         * 中国大陆的身份证正则
         */
        const val CHINESE_ID_CARD_REGEX = "^(\\d{15}$|^\\d{18}$|^\\d{17}(\\d|X|x))$"

        /**
         * 台湾的身份证正则
         */
        const val TW_ID_CARD_REGEX = "^.*[a-zA-Z0-9].*$"

        /**
         * 字母正则
         */
        const val LETTER_REGEX = "^[a-zA-Z]+$"


        val mobilePhonesByCountry = mapOf(
            1 to "^(00){0,1}(1){1}\\d{10,12}$",
            7 to "^(00){0,1}(7){1}[13489]\\d{9,11}$",
            20 to "^(00){0,1}(20){1}\\d{6,12}$",
            27 to "^(00){0,1}(27){1}\\d{6,12}$",
            30 to "^(00){0,1}(30){1}\\d{6,12}$",
            31 to "^(00){0,1}(31){1}6\\d{8}$",
            32 to "^(00){0,1}(32){1}\\d{6,12}$",
            33 to "^(00){0,1}(33){1}(\\d{6}|\\d{8,9})$",
            34 to "^(00){0,1}(34){1}\\d{6,12}$",
            36 to "^(00){0,1}(36){1}\\d{6,12}$",
            39 to "^(00){0,1}(39){1}[37]\\d{8,11}$",
            40 to "^(00){0,1}(40){1}\\d{6,12}$",
            41 to "^(00){0,1}(41){1}\\d{6,12}$",
            43 to "^(00){0,1}(43){1}\\d{6,12}$",
            44 to "^(44)[0-9]{10}$",
            45 to "^(00){0,1}(45){1}\\d{6,12}$",
            46 to "^(00){0,1}(46){1}[124-7](\\d{8}|\\d{10}|\\d{12})$",
            47 to "^(00){0,1}(47){1}\\d{6,12}$",
            48 to "^(00){0,1}(48){1}\\d{6,12}$",
            49 to "^(00){0,1}(49){1}1(\\d{5,6}|\\d{9,12})$",
            51 to "^(00){0,1}(51){1}\\d{6,12}$",
            52 to "^(00){0,1}(52){1}\\d{6,12}$",
            54 to "^(00){0,1}(54){1}\\d{6,12}$",
            55 to "^(00){0,1}(55){1}\\d{6,12}$",
            56 to "^(00){0,1}(56){1}\\d{6,12}$",
            57 to "^(00){0,1}(57){1}\\d{6,12}$",
            58 to "^(00){0,1}(58){1}\\d{6,12}$",
            60 to "^60\\d{9,10}$",
            61 to "^(00){0,1}(61){1}4\\d{8,9}$",
            62 to "^62\\d{10,11}$",
            63 to "^(00){0,1}(63){1}[24579](\\d{7,9}|\\d{12})$",
            64 to "^(00){0,1}(64){1}[278]\\d{7,9}$",
            65 to "^65\\d{8}$",
            66 to "^\\66[6-9][0-9]{9}$",
            76 to "^(76|77)(\\d{9}|\\d{10})$",
            77 to "^(76|77)(\\d{9}|\\d{10})$",
            81 to "^(\\+?81|0)\\d{1,4}[ -]?\\d{1,4}[ -]?\\d{4}$",
            82 to "^\\82(?  to10|11|16|17|18|19)[0-9]{8}$",
            84 to "^84[35789]\\d{8}$",
//            86 to "^(86)[1][3,4,5,7,8][0-9]{9}$",
            90 to "^(00){0,1}(90){1}\\d{6,12}$",
            91 to "^91[6-9]\\d{9}$",
            92 to "^92\\d{10}$",
            94 to "^(00){0,1}(94){1}\\d{6,12}$",
            212 to "^(00){0,1}(212){1}\\d{6,12}$",
            216 to "^(00){0,1}(216){1}\\d{6,12}$",
            220 to "^(00){0,1}(220){1}\\d{6,15}$",
            221 to "^(00){0,1}(221){1}\\d{6,15}$",
            222 to "^(00){0,1}(222){1}\\d{6,15}$",
            223 to "^(00){0,1}(223){1}\\d{6,15}$",
            224 to "^(00){0,1}(224){1}\\d{6,15}$",
            226 to "^(00){0,1}(226){1}\\d{6,15}$",
            227 to "^(00){0,1}(227){1}\\d{6,15}$",
            228 to "^(00){0,1}(228){1}\\d{6,15}$",
            229 to "^(00){0,1}(229){1}\\d{6,15}$",
            230 to "^(00){0,1}(230){1}\\d{6,15}$",
            232 to "^(00){0,1}(232){1}\\d{6,15}$",
            234 to "^(00){0,1}(234){1}\\d{6,12}$",
            235 to "^(00){0,1}(235){1}\\d{6,15}$",
            237 to "^(00){0,1}(237){1}\\d{6,15}$",
            238 to "^(00){0,1}(238){1}\\d{6,15}$",
            240 to "^240[25]\\d{8}$",
            241 to "^(00){0,1}(241){1}\\d{6,15}$",
            244 to "^(00){0,1}(244){1}\\d{6,15}$",
            245 to "^(00){0,1}(245){1}\\d{6,15}$",
            248 to "^(00){0,1}(248){1}\\d{6,12}$",
            250 to "^(00){0,1}(250){1}\\d{6,15}$",
            253 to "^(00){0,1}(253){1}\\d{6,15}$",
            254 to "^(00){0,1}(254){1}\\d{6,15}$",
            255 to "^(00){0,1}(255){1}\\d{6,15}$",
            256 to "^(00){0,1}(256){1}\\d{6,15}$",
            258 to "^(00){0,1}(258){1}\\d{6,15}$",
            260 to "^(00){0,1}(260){1}\\d{6,15}$",
            261 to "^(00){0,1}(261){1}\\d{6,15}$",
            263 to "^(00){0,1}(263){1}\\d{6,15}$",
            264 to "^(00){0,1}(264){1}\\d{6,15}$",
            265 to "^(00){0,1}(265){1}\\d{6,15}$",
            266 to "^(00){0,1}(266){1}\\d{6,15}$",
            268 to "^(00){0,1}(268){1}\\d{6,15}$",
            269 to "^(00){0,1}(269){1}\\d{6,15}$",
            351 to "^(00){0,1}(351){1}\\d{6,12}$",
            352 to "^(00){0,1}(352){1}\\d{6,12}$",
            353 to "^(00){0,1}(353){1}\\d{6,12}$",
            355 to "^(00){0,1}(355){1}\\d{6,15}$",
            357 to "^(00){0,1}(357){1}\\d{6,15}$",
            358 to "^(00){0,1}(358){1}\\d{6,12}$",
            359 to "^(00){0,1}(359){1}\\d{6,12}$",
            370 to "^(00){0,1}(370){1}\\d{6,12}$",
            371 to "^(00){0,1}(371){1}\\d{6,15}$",
            372 to "^(00){0,1}(372){1}\\d{6,12}$",
            373 to "^(00){0,1}(373){1}\\d{6,15}$",
//            "" 375  to "^375\d{9}$",
            380 to "^380(50|63|66|67|73|9[1-9])\\d{7}$",
            381 to "^(00){0,1}(381){1}\\d{6,12}$",
            385 to "^(00){0,1}(385){1}\\d{6,15}$",
            386 to "^(00){0,1}(386){1}\\d{6,15}$",
            421 to "^(00){0,1}(421){1}\\d{6,15}$",
            501 to "^(00){0,1}(501){1}\\d{6,12}$",
            502 to "^(00){0,1}(502){1}\\d{6,15}$",
            503 to "^(00){0,1}(503){1}\\d{6,15}$",
            504 to "^(00){0,1}(504){1}\\d{6,15}$",
            505 to "^(00){0,1}(505){1}\\d{6,15}$",
            506 to "^(00){0,1}(506){1}\\d{6,15}$",
            507 to "^(00){0,1}(507){1}\\d{6,12}$",
            591 to "^(00){0,1}(591){1}\\d{6,15}$",
            592 to "^(00){0,1}(592){1}\\d{6,15}$",
            597 to "^(00){0,1}(597){1}\\d{6,15}$",
            598 to "^(00){0,1}(598){1}\\d{6,15}$",
            673 to "^(00){0,1}(673){1}\\d{6,15}$",
            675 to "^(00){0,1}(675){1}\\d{6,15}$",
            687 to "^687[7-9]\\d{5}$",
            852 to "^\\852[569]\\d{7}$",
            853 to "^853[68]\\d{7}$",
            855 to "^(00){0,1}(855){1}\\d{6,12}$",
            886 to "^\\8869[0-9]{8}$",
            960 to "^(00){0,1}(960){1}\\d{6,12}$",
            962 to "^(00){0,1}(962){1}\\d{6,12}$",
            965 to "^965[569]\\d{7}$",
            966 to "^(00){0,1}(966){1}\\d{6,12}$",
            967 to "^(00){0,1}(967){1}\\d{6,15}$",
            968 to "^(00){0,1}(968){1}\\d{6,15}$",
            970 to "^(00){0,1}(970){1}\\d{6,15}$",
            971 to "^(00){0,1}(971){1}\\d{6,12}$",
            972 to "^(00){0,1}(972){1}\\d{6,12}$",
            973 to "^(00){0,1}(973){1}\\d{6,15}$",
            974 to "^(00){0,1}(974){1}\\d{6,12}$",
            976 to "^(00){0,1}(976){1}\\d{6,12}$",
            992 to "^992\\d{9}$",
            993 to "^993\\d{8}$",
            994 to "^994\\d{9}$",
            995 to "^(00){0,1}(995){1}\\d{6,15}$",
            996 to "^996\\d{9}$",
            998 to "^998(33|90|91|93|94|97|88)\\d{7}$",
            1242 to "^(00){0,1}(1242){1}\\d{6,12}$",
            1284 to "^(00){0,1}(1284){1}\\d{6,12}$",
            1345 to "^(00){0,1}(1345){1}\\d{6,15}$",
            1473 to "^(00){0,1}(1473){1}\\d{6,15}$",
            1868 to "^(00){0,1}(1868){1}\\d{6,15}$",
            1876 to "^(00){0,1}(1876){1}\\d{6,15}$"
        )

        /**
         * 判断字符串是否符合正则表达式
         */
        @JvmStatic
        fun match(str: String, regex: String): Boolean {
            return Pattern.matches(regex, str)
        }

        /**
         * 判断是否是字母
         */
        fun checkChar(value: String): Boolean {
            val pattern = Pattern.compile("[a-z|A-Z]+")
            return pattern.matcher(value).matches()
        }

        /**
         * 判断是否为整数
         */
        fun isInteger(value: String): Boolean {
            val pattern = Pattern.compile("^[-\\+]?[\\d]+$")
            return pattern.matcher(value).matches()
        }

    }

}